package com.koron.order.cockpitStats.business.bean.vo;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.text.NumberFormat;

/**
 * @ClassName PlanStatsGatherVo
 * @description 计划统计
 * @Author zhouj
 * @Date 2022/5/25 11:14
 */
@Data
public class PlanStatsGatherVo {

    @ApiModelProperty("大修计划完成数")
    private int overhaulDone;

    @ApiModelProperty("大修计划总数")
    private int overhaulTotal;

    @ApiModelProperty("大修计划完成率")
    private String overhaulDoneRate;

    @ApiModelProperty("计划检修计划完成数")
    private int repairDone;

    @ApiModelProperty("计划检修计划总数")
    private int repairTotal;

    @ApiModelProperty("计划检修计划完成率")
    private String repairDoneRate;

    @ApiModelProperty("试验计划完成数")
    private int experimentDone;

    @ApiModelProperty("试验计划总数")
    private int experimentTotal;

    @ApiModelProperty("试验计划完成率")
    private String experimentDoneRate;

    public String getOverhaulDoneRate() {
        //仅在json返回处理
        return dealRate(overhaulDone, overhaulTotal);
    }

    public String getRepairDoneRate() {
        return dealRate(repairDone, repairTotal);
    }

    public String getExperimentDoneRate() {
        return dealRate(experimentDone, experimentTotal);
    }

    public String dealRate(int done, int total) {
        //仅在json返回处理
        if (total == 0 || done == 0) {
            return "0";
        }
        //isFinishOnTime/total
        // 创建一个数值格式化对象
        NumberFormat numberFormat = NumberFormat.getInstance();
        // 设置精确到小数点后2位
        numberFormat.setMaximumFractionDigits(2);
        return numberFormat.format((float) done / (float) total * 100);
    }

}
